﻿using System;

// 飞行行为接口
interface IFlyBehavior
{
    void Fly();
}

// 叫行为接口
interface IQuackBehavior
{
    void Quack();
}

// 具体飞行行为：能飞
class FlyWithWings : IFlyBehavior
{
    public void Fly() => Console.WriteLine("用翅膀飞行");
}

// 具体飞行行为：不会飞
class FlyNoWay : IFlyBehavior
{
    public void Fly() => Console.WriteLine("不会飞");
}

// 具体叫行为：呱呱叫
class Quack : IQuackBehavior
{
    public void Quack() => Console.WriteLine("呱呱叫");
}

// 具体叫行为：吱吱叫
class Squeak : IQuackBehavior
{
    public void Quack() => Console.WriteLine("吱吱叫");
}

// 鸭子抽象类
abstract class Duck
{
    protected IFlyBehavior flyBehavior;
    protected IQuackBehavior quackBehavior;

    public Duck() { }

    public abstract void Display();

    public void PerformFly() => flyBehavior.Fly();

    public void PerformQuack() => quackBehavior.Quack();

    public void Swim() => Console.WriteLine("所有鸭子都会游泳");
}

// 具体鸭子：绿头鸭
class MallardDuck : Duck
{
    public MallardDuck()
    {
        flyBehavior = new FlyWithWings();
        quackBehavior = new Quack();
    }

    public override void Display() => Console.WriteLine("我是绿头鸭");
}

// 具体鸭子：橡皮鸭
class RubberDuck : Duck
{
    public RubberDuck()
    {
        flyBehavior = new FlyNoWay();
        quackBehavior = new Squeak();
    }

    public override void Display() => Console.WriteLine("我是橡皮鸭");
}

// 测试类
class Program
{
    static void Main(string[] args)
    {
        Duck mallard = new MallardDuck();
        mallard.Display();
        mallard.Swim();
        mallard.PerformFly();
        mallard.PerformQuack();

        Console.WriteLine();

        Duck rubber = new RubberDuck();
        rubber.Display();
        rubber.Swim();
        rubber.PerformFly();
        rubber.PerformQuack();
    }
}